package com.cictec.middleware.commons.utils;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadUtils {

	public static ThreadPoolExecutor getFixedThreadPool(String threadName, int nThreads){
		return (ThreadPoolExecutor)Executors.newFixedThreadPool(nThreads, new ThreadFactory() {
			 AtomicInteger sn = new AtomicInteger();

			public Thread newThread(Runnable r) {
				SecurityManager s = System.getSecurityManager();
				ThreadGroup group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
				Thread t = new Thread(group, r);
				t.setName(threadName +"-" + sn.incrementAndGet());
				// t.setName("point-execute-thread-" + sn.incrementAndGet());
				return t;
			}
		});
	}
}
